package com.ly.designpatten.single;

/**
 * @Classname LazySingleUnsafe
 * @Description TODO
 * @Date 2020/10/5 14:25
 * @Author 冷心影翼
 */
public class LazySingleUnsafe {

	private static LazySingleUnsafe lazySingleUnsafe;

	private LazySingleUnsafe() {

	}

	public static LazySingleUnsafe getInstance() {
		if(lazySingleUnsafe == null) {
			lazySingleUnsafe = new LazySingleUnsafe();
		}
		return lazySingleUnsafe;
	}
}

class TestLazySingleUnsafe {
	public static void main(String[] args) {
		LazySingleUnsafe lazySingleUnsafe1 = LazySingleUnsafe.getInstance();
		LazySingleUnsafe lazySingleUnsafe2 = LazySingleUnsafe.getInstance();
		System.out.println(lazySingleUnsafe1 == lazySingleUnsafe2);

		LazySingleUnsafe[] lazySingleUnsafe3 = new LazySingleUnsafe[2];
		new Thread(()->{
			lazySingleUnsafe3[0] = LazySingleUnsafe.getInstance();
		}).start();
		new Thread(()->{
			lazySingleUnsafe3[1] = LazySingleUnsafe.getInstance();
		}).start();
		System.out.println(lazySingleUnsafe3[0] == lazySingleUnsafe3[1]);
	}
}